#!/bib/bash

# 创建zabbix的运行用户，用root启动时会自动切换到zabbix用户运行
groupadd -r zabbix
useradd -r -g zabbix zabbix

# 安装依赖包
yum -y install net-snmp-devel libssh2-devel libevent-devel java-devel curl-devel

# 解压安装
tar xf zabbix-5.2.5.tar.gz

# 切换到安装目录
cd zabbix-5.2.5/

# zabbix配置
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-ssh2 --enable-java

# zabbix编译安装
make && make install

#创建用户数据库和授权
/usr/local/mysql/bin/mysql -uroot -p666666 -e "create database zabbix character set utf8 collate utf8_bin;"
/usr/local/mysql/bin/mysql -uroot -p666666 -e "grant all privileges on zabbix.* to zabbix@'%' identified by 'password'"

#导入zabbix数据库用户
mysql -uzabbix -ppassword zabbix < ~/zabbix-5.2.5/database/mysql/schema.sql
mysql -uzabbix -ppassword zabbix < ~/zabbix-5.2.5/database/mysql/images.sql
mysql -uzabbix -ppassword zabbix < ~/zabbix-5.2.5/database/mysql/data.sql

# 安装zabbix web
mkdir /usr/local/httpd/htdocs/zabbix
cp -a ui/* /usr/local/httpd/htdocs/zabbix

# 导入zabbix_server.conf 和 zabbix_agent.conf
cp -rf ~/zabbix_* /usr/local/etc/

# 导入以下库zabbix运行的时候要不找不到
echo "/usr/local/mysql/lib" >> /etc/ld.so.conf

# 导入zabbix Web配置文件
cp -rf ~/zabbix.conf.php /usr/local/httpd/htdocs/zabbix/conf/

# 导入字体
cp -rf ~/DejaVuSans.ttf /usr/local/httpd/htdocs/zabbix/assets/fonts

# zabbix系统服务管理
cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
service zabbix_server start
service zabbix_agentd start

